package com.olocat.cjx.nsims.util

import com.fasterxml.jackson.annotation.JsonProperty
import java.util.Date

/**
 * Json 返回主体工具
 *
 * @author olocat
 * @date 2020-2-16
 */

class Response private constructor(val result: Any?, val message: String, val timestamp: Long, val code: Int) {

    @JsonProperty("_status")
    var status: Int = 0
    @JsonProperty("_header")
    var header: Any? = null

    companion object {
        fun builder(): Response {
            return Response(null, "", Date().time, 0)
        }

        fun builder(data: Any?): Response {
            return Response(data, "", Date().time, 0)
        }

        fun builder(data: Any?, message: String): Response {
            return Response(data, message, Date().time, 0)
        }

        fun builder(data: Any?, code: Int): Response {
            return Response(data, "", Date().time, code)
        }

        fun builder(data: Any?, message: String, code: Int): Response {
            return Response(data, message, Date().time, code)
        }

        fun builder(data: Any?, code: Int, header: Any?): Response {
            val re = Response(data, "", Date().time, code)
            re.status = code
            re.header = header
            return re
        }
    }
}